package com.hao.tool.extra.poi.excel;


import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;


/**
 * Excel表格构造
 * Created by haol on 2017/4/18.
 */
public class BuildExcelUtil {


    //下载组织成员信息表
    public static HSSFWorkbook createContainMsg1(String[][] members, String name, String sheetName, String[] head) {

        int strLength = head.length;

        HSSFWorkbook workbook = new HSSFWorkbook();
        ExcelRow excelRow = new ExcelRow(workbook);

        HSSFSheet sheet = workbook.createSheet(sheetName);
        sheet.setDefaultColumnWidth(30);
        ExcelCellStyle cellStyle = new ExcelCellStyle(workbook);
        SetValidation validation = new SetValidation();
        sheet.setDefaultColumnWidth(20);
        HSSFCell cell;
        CellRangeAddress range;
        HSSFRow row;
        int rownum = 0;
        //第0行
        excelRow.createRow(sheet, rownum, name, strLength, 500);
        rownum++;
        //第1行
        // excelRow.createRow(sheet, 1, "请注意保护隐私", strLength, 300);
        //第2行
        excelRow.createRowHead(sheet, head, rownum);
        rownum++;
        for (int i = 0; i < members.length; i++) {
            HSSFRow rows = sheet.createRow(rownum);
            for (int j = 0; j < head.length; j++) {
                cell = rows.createCell(j);
                if (j == head.length - 1 && "异常".equals(members[i][j])) {
                    cell.setCellStyle(cellStyle.headStyle2());
                }
                cell.setCellValue(members[i][j]);
            }
            rownum++;
        }
        return workbook;
    }

}
